/*
 *email: chen983@sina.com
 */
#ifndef _ORACLE_READER_IMP_H__
#define _ORACLE_READER_IMP_H__

#define SQLCA_STORAGE_CLASS extern
#define ORACA_STORAGE_CLASS extern
#include <stdio.h>
#include <sqlca.h>
#include <sqlda.h>
#include <sqlcpr.h>

#include "reader.h"

namespace Oracle
{

struct BindParameter
{
	string value;
	int direct;	//1 input; 2 output;
	char *v;
	string *output;
};

class Readerimp:public Reader
{
private:
	friend class Command;
	Readerimp(void *ctx, Command &command, bool open=true);
	virtual ~Readerimp();

public:
	virtual void open();
	virtual void close(bool deleteThis=true);
	virtual bool read();
	virtual void bindParameter(const char *value);
	virtual void bindOutputParameter(string &value);

private:
	void daAllocate(int size, int max_vname_len, int max_iname_len);
	
	void selectList();
	void bindList();
	
	void clear();
	void clearBindDes();
	
private:
	unsigned int sqlctx;;
	
	void *_select_des;
	void *_bind_des;
	
	vector<BindParameter> bindVariables;	
};

};
#endif
